<?php
namespace app\goods\model;
use \app\common\library\Model;

class GoodsOrder extends Model
{
    protected $append = [
        'goods_type_name',
        'status_name',
        'stage_name'
    ];


    protected $type = [
        'stock_attrs' => 'json'
    ];

	// 订单跟踪
    public function trace(){
        return $this->hasMany('app\\goods\\model\\GoodsOrderTrace','order_no', 'order_no');
    }

    public function getGoodsTypeNameAttr($value, $data) {
        return $data['goods_type'] ? '虚拟' : '实物';
    }


    public function getStatusNameAttr($value, $data) {
        $return = '';
        switch ($data['status']) {
            case -1 :
                $return = '已撤销';
                break;
            case 0 :
                $return = '进行中';
                break;
            case 1 :
                $return = '已完成';
                break;
            default :
                break;
        }
        return $return;
    }

    public function getStageNameAttr($value, $data) {
        //（-1：已取消；0：待确认；1：待发货；2：待收货；99：已完成）
        $return = '';
        switch ($data['stage']) {
            case -1 :
                $return = '已取消';
                break;
            case 0 :
                $return = '待确认';
                break;
            case 1 :
                $return = '待发货';
                break;
            case 2 :
                $return = '待收货';
                break;
            case 99 :
                $return = '已完成';
                break;
            default :
                break;
        }
        return $return;
    }


    public function StockTicketInfo() {
        return $this->hasOne("app\\goods\\model\\GoodsStockTicket", 'id', 'stock_ticket_id');
    }



}
